import { Controller, Get } from '@nestjs/common';
import { UserService } from './modules/user/user.service';
import { User } from './modules/user/models/user.entity';

@Controller()
export class AppController {
  constructor(private readonly userService: UserService) {}

  @Get('/create')
  async create(): Promise<boolean> {
    return await this.userService.create({
      name: 'test',
      desc: 'test',
      tel: '12345678901',
      password: '123456',
      account: 'test',
    });
  }
  @Get('/del')
  async del(): Promise<boolean> {
    return await this.userService.del('e6978083-1303-47b2-8139-4be046e0265b');
  }
  @Get('/update')
  async update(): Promise<boolean> {
    return await this.userService.update(
      '6c1502d8-a34c-4208-8442-57c98a8974af',
      {
        name: 'test233',
      },
    );
  }
  @Get('/find')
  async find(): Promise<User> {
    const user = await this.userService.find(
      '6c1502d8-a34c-4208-8442-57c98a8974af',
    );
    if (!user) {
      throw new Error('未找到对应的用户');
    }
    return user;
  }
}
